package office.dao.workflow;

import java.util.Iterator;
import java.util.Map;

import platform.common.dao.impl.BaseDomainProviderImpl;

public class RemindDP extends BaseDomainProviderImpl{
	
	//方法描述: 根据条件获取待办任务列表
	public String findRemindByCondition(Map<String ,Object> condMap){
		StringBuffer strBuf = new StringBuffer();
		strBuf.append(" from "+ this.getDomainClassName() + " where 1=1 ");
		Iterator<String> it = condMap.keySet().iterator();
		while(it.hasNext()){
			String str = (String)it.next();
			if(str.equals("id")){
				strBuf.append(" and id ='"+condMap.get(str)+"' ");
			}
			if(str.equals("name")){
				strBuf.append(" and name like '%"+condMap.get(str)+"%' ");
			}
			if(str.equals("objId")){
				strBuf.append(" and objId ='"+condMap.get(str)+"' ");
			}
			if(str.equals("objClassName")){
				strBuf.append(" and objClassName ='"+condMap.get(str)+"' ");
			}
			if(str.equals("sendDate")){
				strBuf.append(" and sendDate ='"+condMap.get(str)+"' ");
			}
			if(str.equals("remindUser")){
				strBuf.append(" and remindUser ='"+condMap.get(str)+"' ");
			}
			if(str.equals("lookDate")){
				strBuf.append(" and lookDate ='"+condMap.get(str)+"' ");
			}
			if(str.equals("handleState")){
				strBuf.append(" and handleState ='"+condMap.get(str)+"' ");
			}
//			strBuf.append(" order by handleState asc ");
		}
		return strBuf.toString();
	}
	
	//方法描述: 根据条件获取待办任务列表
	public String findRemindCountByCondition(Map<String ,Object> condMap){
		StringBuffer strBuf = new StringBuffer();
		strBuf.append("select count(*) from "+ this.getDomainClassName() + " where 1=1 ");
		Iterator<String> it = condMap.keySet().iterator();
		while(it.hasNext()){
			String str = (String)it.next();
			if(str.equals("id")){
				strBuf.append(" and id ='"+condMap.get(str)+"' ");
			}
			if(str.equals("name")){
				strBuf.append(" and name like '%"+condMap.get(str)+"%' ");
			}
			if(str.equals("objId")){
				strBuf.append(" and objId ='"+condMap.get(str)+"' ");
			}
			if(str.equals("objClassName")){
				strBuf.append(" and objClassName ='"+condMap.get(str)+"' ");
			}
			if(str.equals("sendDate")){
				strBuf.append(" and sendDate ='"+condMap.get(str)+"' ");
			}
			if(str.equals("remindUser")){
				strBuf.append(" and remindUser ='"+condMap.get(str)+"' ");
			}
			if(str.equals("lookDate")){
				strBuf.append(" and lookDate ='"+condMap.get(str)+"' ");
			}
			if(str.equals("handleState")){
				strBuf.append(" and handleState ='"+condMap.get(str)+"' ");
			}
		}
		return strBuf.toString();
	}
	public String deleteRemind(Map<String ,Object> condMap){
		StringBuffer strBuf = new StringBuffer();
		strBuf.append("delete from Remind where 1=2 ");
		Iterator<String> it = condMap.keySet().iterator();
		boolean bool = false;
		if(it.hasNext()){
			strBuf.append(" or (");
			while(it.hasNext()){
				String str = (String)it.next();
				if(str.equals("handleState") && condMap.get(str) != null){
					if(bool){
						strBuf.append(" and ");
					}
					strBuf.append(" handleState ="+condMap.get(str)+" ");
					bool = true;
				}
				if(str.equals("remindUser") && condMap.get(str) != null){
					if(bool){
						strBuf.append(" and ");
					}
					strBuf.append(" remindUser = '"+condMap.get(str)+"'");
					bool = true;
				}
			}
			strBuf.append(" )");
		}
		return strBuf.toString();
	}
	
	public String updateAllRemindToRead(Map<String ,Object> condMap){
		StringBuffer strBuf = new StringBuffer();
		strBuf.append("update Remind set handleState=1 where 1=2 ");
		Iterator<String> it = condMap.keySet().iterator();
		boolean bool = false;
		if(it.hasNext()){
			strBuf.append(" or (");
			while(it.hasNext()){
				String str = (String)it.next();
				if(str.equals("handleState") && condMap.get(str) != null){
					if(bool){
						strBuf.append(" and ");
					}
					strBuf.append(" handleState ="+condMap.get(str)+" ");
					bool = true;
				}
				if(str.equals("remindUser") && condMap.get(str) != null){
					if(bool){
						strBuf.append(" and ");
					}
					strBuf.append(" remindUser = '"+condMap.get(str)+"'");
					bool = true;
				}
			}
			strBuf.append(" )");
		}
		return strBuf.toString();
	}
}
